#include<stdio.h>
#include<stdlib.h>
struct data
{
	int n;
	struct data *p;
};
int main()
{
	int m;
	struct data *head=(struct data*)malloc(sizeof(struct data));
 	struct data *p1;
 	p1=head;
 	int s=0;
 	while(scanf("%d",&m)!=EOF)
 	{
 		if(m==0)
 		{
 			break;
		}
		s++;
 		struct data *p2=(struct data*)malloc(sizeof(struct data));
 		p2->n=m;
 		p1->p=p2;
 		p1=p2;
	}
	head=head->p;
	p1->p=NULL;
	struct data *p3,*p4;
	p3=head;
	p4=head;
	struct data *tail;
	tail=p1;
	while(p4!=tail)
	{
		
		if(p4->n<0)
		{
			if(p4==head)
			{
				struct data *r;
				r=head;
				head=head->p;
				p4=p4->p;
				p3=p4;
				p1->p=r;
				r->p=NULL;
				p1=p1->p;
				
			}
			else
			{
				p3->p=p4->p;
				struct data *t;
				t=p4;
				p4=p3->p;
				p1->p=t;
				t->p=NULL;
				p1=t;
			}
		}
		else
		{
			p3=p4;
			p4=p4->p;
		}
		
	}
	while(head!=NULL)
	{
		
		printf("%d ",head->n);
		head=head->p;
	}
 	return 0;
}
